import { storage } from '@/utils/tools'

// app vuex
const state = {
  menuList: [],
  sidebarList: [],
  sidebar: {
    opened: storage.getLocal('sidebarStatus') ? !!storage.getLocal('sidebarStatus') : true,
    withoutAnimation: false
  },
  userInfo: {
    overallOrganizeName: '',
    overallDutyName: '',
    overallRealName: '',
    overallUserName: ''
  }
}

const mutations = {
  setMenuList: (store, data) => {
    store.menuList = data;
  },
  setSidebarList: (store, data) => {
    store.sidebarList = data;
  },
  setUserInfo: (store, data) => {
    store.userInfo = data;
  },
  TOGGLE_SIDEBAR: state => {
    state.sidebar.opened = !state.sidebar.opened
    state.sidebar.withoutAnimation = false
    if (state.sidebar.opened) {
      storage.setLocal('sidebarStatus', 1)
    } else {
      storage.setLocal('sidebarStatus', 0)
    }
  },
}

const actions = {
  setMenuList({ commit }, data) {
    commit('setMenuList', data)
  },
  setSidebarList({ commit }, data) {
    commit('setSidebarList', data)
  },
  setUserInfo({ commit }, data) {
    commit('setUserInfo', data)
  },
  toggleSideBar({ commit }) {
    commit('TOGGLE_SIDEBAR')
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
